package com.hy.hongying.third;

import com.baidu.aip.contentcensor.AipContentCensor;
import org.json.JSONObject;

/**
 * @program: IdlerApi
 * @description:
 * @author: Feri(邢朋辉)
 * @create: 2021-07-06 10:27
 */
public class BaiduCensorUtil {
    //设置APPID/AK/SK
    public static final String APP_ID = "17214730";
    public static final String API_KEY = "WnrcZnQNbveI7UG7sDroOm1K";
    public static final String SECRET_KEY = "FUui3jN440l9eLN8B335C3VS62HvtafU";

    private static AipContentCensor client;
    static {
        client = new AipContentCensor(APP_ID, API_KEY, SECRET_KEY);
    }
    /**
     * 文本审核
     * @param msg 要审核的字符串*/
    public static boolean textCensor(String msg){
        JSONObject object=client.textCensorUserDefined(msg);
        return object.getInt("conclusionType")==1;
    }
    /**
     * 文本审核*/
    public static boolean textCensor(String... msg){
        boolean r=true;
        for(String s:msg){
            JSONObject object=client.textCensorUserDefined(s);
            if(object.getInt("conclusionType")!=1){
                r=false;
                break;
            }
        }
        return r;
    }
    /**
     * 图片审核
     * */
    public static boolean imageCensor(byte[] data){
        JSONObject object=client.imageCensorUserDefined(data,null);
        return object.getInt("conclusionType")==1;
    }
}
